package cc.kzc.adminauth.common;

import java.io.Serializable;

import lombok.Data;

@Data
public class BaseResponse implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1L;

	private Integer code = ErrorCode.ERR.code();
	private String msg = "";

	private Integer count = null;
	private Object result = null;

	protected BaseResponse(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public static BaseResponse fail(ErrorCode errorCode, String... strings) {
		StringBuilder sb = new StringBuilder();
		sb.append(errorCode.getMessage());
		for (String str : strings) {
			sb.append("|").append(str);
		}
		return new BaseResponse(errorCode.code(), sb.toString());
	}

	public static BaseResponse fail(String... strings) {
		return fail(ErrorCode.ERR, strings);
	}

	public static BaseResponse success() {
		return new BaseResponse(ErrorCode.SUCCESS.code(), ErrorCode.SUCCESS.getMessage());
	}

	public static BaseResponse success(Object ret) {
		BaseResponse resp = success();
		resp.setResult(ret);
		return resp;
	}

}
